package edu.jsnu.service.ticket.schedule.dto;

import edu.jsnu.service.ticket.schedule.domain.Schedule;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@Getter
@Setter
public class ScheduleReceive {
    private Integer id;

    private String scheduleTime;

    private Double price;

    private Integer place;

    private String remark;

    private Integer filmId;

    private String title;

    private Integer duration;

    private Integer status;

    private Integer timeFlag;

    public static Schedule receive2Schedule(ScheduleReceive receive){
        Schedule schedule = new Schedule();
        if (!StringUtils.isEmpty(receive.getScheduleTime())){
            String[] times = receive.getScheduleTime().split("~");
            BeanUtils.copyProperties(receive, schedule);
            try {
                //转换日期格式
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                schedule.setStartTime(sdf.parse(times[0]));
                schedule.setEndTime(sdf.parse(times[1]));
                return schedule;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }else {
            BeanUtils.copyProperties(receive, schedule);
            return schedule;
        }
        return schedule;
    }

    public static ScheduleReceive scheduleShow2Receive(ScheduleShow schedule){
        ScheduleReceive receive = new ScheduleReceive();
        BeanUtils.copyProperties(schedule, receive);
        if (!StringUtils.isEmpty(schedule.getStartTime())){
            receive.setScheduleTime(schedule.getStartTime() + " ~ "+schedule.getEndTime());
        }
        return receive;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getScheduleTime() {
        return scheduleTime;
    }

    public void setScheduleTime(String scheduleTime) {
        this.scheduleTime = scheduleTime;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Integer getPlace() {
        return place;
    }

    public void setPlace(Integer place) {
        this.place = place;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getFilmId() {
        return filmId;
    }

    public void setFilmId(Integer filmId) {
        this.filmId = filmId;
    }

    public Integer getDuration() {
        return duration;
    }

    public void setDuration(Integer duration) {
        this.duration = duration;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getTimeFlag() {
        return timeFlag;
    }

    public void setTimeFlag(Integer timeFlag) {
        this.timeFlag = timeFlag;
    }
}
